package com.cmb.lk50.controller;

import com.cmb.lk50.common.AccessLog;
import com.cmb.lk50.common.extractor.BodyParamExtractor;
import com.cmb.lk50.common.extractor.UrlParamExtractor;
import com.cmb.lk50.pojo.CustomBody;
import com.cmb.lk50.pojo.Request;
import com.cmb.lk50.sink.kafka.IpKeyGenerator;
import org.springframework.web.bind.annotation.*;

/**
 * Author       : 蒋俊钊 80256973
 * Date         : 2020/7/22
 * Copyright    (C) ChinaMerchantsBank
 */
@RestController
public class ServletController {

    @GetMapping("/url-log")
    @AccessLog(extractor = UrlParamExtractor.class)
    public String test1(@RequestParam(name = "p1") String p1,
                        @RequestParam(name = "p2") String p2,
                        @RequestParam(name = "p3") String p3,
                        @RequestParam(name = "p4") String p4,
                        @RequestParam(name = "p5") String p5,
                        @RequestParam(name = "p6") String p6,
                        @RequestParam(name = "p7") String p7,
                        @RequestParam(name = "p8") String p8,
                        @RequestParam(name = "p9") String p9,
                        @RequestParam(name = "p10") String p10) {
        return p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10;
    }

    @PostMapping("/body-log")
    @AccessLog(extractor = BodyParamExtractor.class, kafkaKeyer = IpKeyGenerator.class, value = CustomBody.class)
    public String test3(@RequestBody Request request) {
        return request.toString();
    }





    @GetMapping("/url")
    public String test2(@RequestParam(name = "p1") String p1,
                        @RequestParam(name = "p2") String p2,
                        @RequestParam(name = "p3") String p3,
                        @RequestParam(name = "p4") String p4,
                        @RequestParam(name = "p5") String p5,
                        @RequestParam(name = "p6") String p6,
                        @RequestParam(name = "p7") String p7,
                        @RequestParam(name = "p8") String p8,
                        @RequestParam(name = "p9") String p9,
                        @RequestParam(name = "p10") String p10) {

        String x = p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10;
        System.out.println(x);
        return x;
    }

    @PostMapping("/body")
    public String test4(@RequestBody Request request) {
        System.out.println(request.toString());
        return request.toString();
    }
}
